<template>
  <el-breadcrumb separator="/">
    <el-breadcrumb-item :to="{ path: '/confirmedPatient' }"
      >确诊病患管理</el-breadcrumb-item
    >
    <el-breadcrumb-item>新建病患</el-breadcrumb-item>
  </el-breadcrumb>
  <el-card label="病患信息">
    <el-form
      ref="form"
      :model="form"
      :label-position="labelPosition"
      label-width="80px"
    >
      <el-form-item label="姓名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item label="身份证号">
        <el-input v-model="form.idCard"></el-input>
      </el-form-item>
      <el-form-item label="电话号码">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>

      <div class="block">
        <el-form-item label="住院时间">
          <el-date-picker
            v-model="form.time"
            type="datetime"
            placeholder="选择日期时间"
            align="right"
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </el-form-item>
      </div>

      <el-form-item label="感染源">
        <el-input v-model="form.source"></el-input>
      </el-form-item>
      <el-form-item label="症状">
        <el-input v-model="form.symbol"></el-input>
      </el-form-item>
      <el-form-item label="诊治医院">
        <el-input v-model="form.hospital"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="addPatient">保存</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>
    
    <script>
import { addPatientApi } from "../api/index1.js";
import { ElMessage } from "element-plus";
export default {
  data() {
    return {
      labelPosition: "left",
      form: {
        name: "",
        idCard: "",
        source: "",
        symbol: "",
        hospital: "",
        time: "",
        phone: "",
      },
    };
  },
  methods: {
    onSubmit() {
      console.log("submit!");
    },
    //6.添加patient的方法
    addPatient() {
      let obj = {
        userName: this.form.name,
        idCard: this.form.idCard,
        phone: this.form.phone,
        onSetTime: this.form.time,
        source: this.form.source,
        symbol: this.form.symbol,
        hospital: this.form.hospital,
      };
      addPatientApi(obj).then((res) => {
        console.log(res);
        // this.formData = {};
        // 2.提示用户添加成功
        if (res.code == 20000) {
          ElMessage({
            message: "添加成功",
            type: "success",
          });
        }
        //   this.$router.back()
        this.$router.push("../views/confirmedPatient");
      });
    },
  },
};
</script>
    
    <style lang="less" scoped>
.el-card {
  margin-top: 20px;
}
.el-form {
  width: 800px;
}
.el-input {
  width: 220px;
}
</style>